Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak predictProblems logic, add test for it #2117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kaulfield23
Copy link
Contributor

Description

This PR fixes predictProblems logic where it shows an error when name value is missing.

Screenshots

People.-.Opera.2024-09-01.13-44-28.mp4

Changes

  • Adds test to predictProblems.spec.ts
  • Changes predictProblems logic

Notes to reviewer

Related issues

Resolves #2114

Copy link
Contributor

@ziggabyte ziggabyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Haeju!! :D

I have played around with this a bit and read the code, and even though it does work for the case you are testing for - this solution, I think, can be made better because it has an unexpected buggy consequence...

If I run your code and import a file without giving selecting a first name, last name or id column, i get "unexpected error". If i do the same thing on main, I get the error "you have not configured identifying columns", which is what should happen...

So, maybe experiment some more and see that it has no unexpected consequences!

@@ -75,6 +63,7 @@ export function predictProblems(
customFields.forEach((field) => {
customFieldsBySlug[field.slug] = field;
});
let isMissingValue = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure this variable is doing so much 😅 If I remove it from the code, the only difference is that I get both unconfigured ID error and "not all rows have identifiers" error, instead of just the latter.

Copy link
Contributor Author

@kaulfield23 kaulfield23 Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for removing unconfigured ID error(yellow box). Thought that it is weird to show yellow box with text "I understand and want to proceed anyway" when there is an error. Should I remove isMissingValue? @ziggabyte

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to do what you've tried to do @kaulfield23, but I think the best way to do it is to write a test that reproduces the problem you found, and then fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardolsson Okay! will do 👍

Copy link
Contributor Author

@kaulfield23 kaulfield23 Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that case is already covered with the test I wrote ( test : returns problem when either the first name or last name value is missing ) . And the case that ziggi found is already covered with another test that already exists ( test : returns problem when ID or name are not configured )

Is there a case that I have not added? @richardolsson

@@ -133,11 +122,13 @@ export function predictProblems(
}
}
hadImpact = true;
} else {
isMissingValue = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me a bit confused - this will be set to true if any "cell" in the sheet is empty, no matter if it is name/id or not.

@richardolsson
Copy link
Member

Nice work @kaulfield23. Can you also write tests for the edge cases you've handled?

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found a regression in this PR (i.e. a bug that was introduced in this PR that doesn't exist on main). It may be the same thing that @ziggabyte pointed out in his previous review, and it still remains after the most recent commit. Below are instructions for how to reproduce it (and separate a comment on how I think it should be tested).

I think this needs to be fixed before this can be merged. But then I think we also need better testing in the future, and I've created a separate issue for this: #2156.

Steps to reproduce

Use a CSV file with this content (note the missing first name on the last row):

ID,FIRST,LAST,EMAIL
4,Clara,Zetkin,[email protected]
,Clara,Zetin,[email protected]
5,,Zetkin,[email protected]

Configure only the first name and the email address, not the ID or last name columns, and then click "VALIDATE"

image

Expected results

The user should be presented with an error message indicating that not enough identifying columns have been configured. This should be caught by predictProblems() and prevent any API requests from being made. This currently works on main.

image

Actual results

The user is presented with an "unknown" error message. An API request is made to the /preview API which immediately fails. This likely happens because predictProblems() finds no errors.

image

Comment on lines +453 to +455
field: 'first_name',
kind: ColumnKind.FIELD,
selected: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try creating another test that is a copy of this one, except that this column is not configured (ColumnKind.UNKNOWN and selected: false). In my experimentation, that seems to not return a problem even though it should return UNCONFIGURED_ID_AND_NAME because not the full name has been configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import: Missing name not caught when ID is also missing
3 participants